
import 'package:flutter/cupertino.dart';
import 'package:flutter_login_animation/home.dart';

import 'detail.dart';
import 'login.dart';
import 'noFoundPage.dart';

class RouterManager {
  static String notFoundPath = '404';
  static String splashPath = '/';
  static String loginPath = '/login';
  static String homePath = '/home';
  static String detail = '/detail';

  static Map<String,WidgetBuilder> routerManagers = {
    //404页面
    notFoundPath: (context) => const NoFoundPage(),
    //启动页
    // splashPath:(context) => Splash(),
    //登录
    loginPath:(context) => LoginScreen(),
    //首页
    homePath:(context) => HomePage(),
    //详情
    detail:(context) => DetailPage(),
  };

  ///路由拦截
  static Route onGeneratRoute<T extends Object>(RouteSettings settings){
    return CupertinoPageRoute(
        settings: settings,
        builder:(context){
          String? name = settings.name;
          if (routerManagers[name] == null) {
            name = notFoundPath;
          }
          Widget widget = routerManagers[name]!(context);

          return widget;
        }
    );
  }
}




